﻿using MiniExcelLibs.Attributes;

namespace Mohe.Scada.Util.S7Parser
{
    [Serializable]
    public class DefinitionSection
    {
        [ExcelIgnore]
        public DefinitionType Type { get; set; }
        [ExcelIgnore]
        public string Raw { get; set; } = "";
        [ExcelColumn(Name = "栏目", Width = 50)]
        public string Name { get; set; }

        [ExcelIgnore]
        public List<DefinitionSection> StructItems;
        [ExcelIgnore]
        public int Size { get; set; }
        [ExcelColumn(Name = "数据类型")]
        public string DataType { get; set; }
        /// <summary>
        /// 偏移比特位
        /// </summary>
        [ExcelIgnore]
        public int Offset { get; set; }
        /// <summary>
        /// 偏移字节
        /// </summary>
        [ExcelColumn(Name = "偏移量")]
        public int Pos { get => Offset / 8; }
        /// <summary>
        /// 起始比特位
        /// </summary>
        [ExcelColumn(Name = "比特位")]
        public int Bit { get => Offset % 8; }

        /// <summary>
        /// 新结构体
        /// </summary>
        [ExcelIgnore]
        public bool IsNewStruct { get; set; }
        /// <summary>
        /// 结构体结束
        /// </summary>
        [ExcelIgnore]
        public bool isEndStruct { get; set; }
        [ExcelColumn(Name = "描述", Width = 50)]
        public string Desc { get; set; }
        /// <summary>
        /// 地址
        /// </summary>
        [ExcelIgnore]
        public string Addr { get; set; }

        public int Len { get; set; }
    }

    public enum DefinitionType
    {
        Unknown,
        UserDefinedType,
        DataBlock,
        Input,
        Output,
    }
}
